package com.zn.znch.yhp.znchv2.common;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateUtil {


    //判断两个时间在n分钟以上,是则TRUE

    /**
     * time1 - time0 >n
     * @param time0 起始时间
     * @param time1 结束时间
     * @param n
     * @return
     */
    public static boolean isWithinTenMinutes(String time0, String time1,int n) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        LocalDateTime data0 = LocalDateTime.parse(time0, formatter);
        LocalDateTime data1 = LocalDateTime.parse(time1, formatter);
        Duration duration = Duration.between(data0, data1);
        long minutes = duration.toMinutes();
        return  minutes > n;
    }

    public static void main(String[] args) {
        System.out.println(isWithinTenMinutes("2024/11/03 12:00:00","2024/11/03 12:10:00",5));
        System.out.println(isWithinTenMinutes("2024/11/03 12:07:00","2024/11/03 12:10:00",5));
        System.out.println(isWithinTenMinutes("2024/11/03 12:20:00","2024/11/03 12:10:00",5));
    }
}
